from django.db import models


# Create your models here.

class Shop(models.Model):
    name = models.CharField(max_length=50)  # 店铺名称
    cover_pic = models.CharField(max_length=255)  # 封面图片
    banner_pic = models.CharField(max_length=255)  # 图标logo
    address = models.CharField(max_length=255)  # 店铺地址
    phone = models.CharField(max_length=255)  # 联系电话
    status = models.IntegerField()  # 状态
    create_at = models.DateTimeField()  # 添加时间
    update_at = models.DateTimeField()  # 修改时间

    def toDict(self):
        shopname = self.name.split("-")
        return {'id':self.id,'name':shopname[0],'shop':shopname[1],'cover_pic':self.cover_pic,'banner_pic':self.banner_pic,'address':self.address,'phone':self.phone,'status':self.status,'create_at':self.create_at.strftime('%Y-%m-%d %H:%M:%S'),'update_at':self.update_at.strftime('%Y-%m-%d %H:%M:%S')}

    # 指定实际表名
    class Meta:
        db_table = "shop"  # 更改表名


class Category(models.Model):
    shop_id = models.IntegerField()  # shop_id
    name = models.CharField(max_length=50)  # 分类名称
    status = models.IntegerField()  # 状态
    create_at = models.DateTimeField()  # 添加时间
    update_at = models.DateTimeField()  # 修改时间

    # 指定实际表名
    class Meta:
        db_table = "category"  # 更改表名


class Product(models.Model):
    shop_id = models.IntegerField()  # 店铺id
    category_id = models.IntegerField()  # 菜品分类id
    cover_pic = models.CharField(max_length=50)  # 菜品图片
    name = models.CharField(max_length=155)  # 名称
    price = models.FloatField()  # 单价(6,2)
    status = models.IntegerField()  # 状态
    create_at = models.DateTimeField()  # 添加时间
    update_at = models.DateTimeField()  # 修改时间

    def toDict(self):
        return {'id':self.id,'shop_id':self.shop_id,'category_id':self.category_id,'cover_pic':self.cover_pic,'name':self.name,'price':self.price,'status':self.status,'create_at':self.create_at.strftime('%Y-%m-%d %H:%M:%S'),'update_at':self.update_at.strftime('%Y-%m-%d %H:%M:%S')}

    # 指定实际表名
    class Meta:
        db_table = "product"  # 更改表名


class Member(models.Model):
    nickname = models.CharField(max_length=50)  # 昵称
    avatar = models.CharField(max_length=255)  # 头像
    mobile = models.CharField(max_length=50)  # 电话
    status = models.IntegerField()  # 状态
    create_at = models.DateTimeField()  # 添加时间
    update_at = models.DateTimeField()  # 修改时间

    # 指定实际表名
    class Meta:
        db_table = "member"  # 更改表名


class Orders(models.Model):
    shop_id = models.IntegerField()  # 店铺id
    member_id = models.IntegerField()  # 会员id
    user_id = models.IntegerField()  # 操作员id
    money = models.FloatField()  # 金额(8,2)
    status = models.IntegerField()  # 订单状态
    payment_status = models.IntegerField()  # 支付状态
    create_at = models.DateTimeField()  # 添加时间
    update_at = models.DateTimeField()  # 修改时间

    # 指定实际表名
    class Meta:
        db_table = "orders"  # 更改表名


class OrderDetail(models.Model):
    order_id = models.IntegerField()  # 订单id号
    product_id = models.IntegerField()  # 菜品id号
    product_name = models.CharField(max_length=50)  # 菜品名称
    price = models.FloatField()  # 单价(6,2)
    quantity = models.IntegerField()  # 数量
    status = models.IntegerField()  # 状态

    # 指定实际表名
    class Meta:
        db_table = "order_detail"  # 更改表名


class Payment(models.Model):
    order_id = models.IntegerField()  # 订单id
    member_id = models.IntegerField()  # 会员id
    money = models.FloatField()  # 金额(8,2)
    type = models.IntegerField()  # 付款方式
    bank = models.IntegerField()  # 收款银行渠道
    status = models.IntegerField()  # 支付状态
    create_at = models.DateTimeField()  # 添加时间
    update_at = models.DateTimeField()  # 修改时间

    # 指定实际表名
    class Meta:
        db_table = "payment"  # 更改表名


class User(models.Model):
    username = models.CharField(max_length=50)  # 登录账号
    nickname = models.CharField(max_length=50)  # 昵称
    password_hash = models.CharField(max_length=100)  # 密码
    password_salt = models.CharField(max_length=50)  # 密码干扰值
    status = models.IntegerField()  # 状态
    create_at = models.DateTimeField()  # 添加时间
    update_at = models.DateTimeField()  # 修改时间

    def toDict(self):
        return {'id':self.id,'username':self.username,'nickname':self.nickname,'password_hash':self.password_hash,'password_salt':self.password_salt,'status':self.status,'create_at':self.create_at.strftime('%Y-%m-%d %H:%M:%S'),'update_at':self.update_at.strftime('%Y-%m-%d %H:%M:%S')}

    # 指定实际表名
    class Meta:
        db_table = "user"  # 更改表名
